home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: atol or strtol ?
- Date: 18 Jan 1996 15:34:14 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>
- References: <4dbobq$763@jupiter.planet.net> <4dk4sc$dmj@spanky.pls.ov.com>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: glenn@ov.com's message of 18 Jan 1996 00:39:40 GMT
-
- In article <4dk4sc$dmj@spanky.pls.ov.com> glenn@ov.com (Fletcher.Glenn@ov.com) writes:
-
- : In article 763@jupiter.planet.net, Chris Kemp <chrisk@paladn.com> writes:
- : >what is the difference between strtol function and atol ?
-
- : Looking at TFM tells me that atol() expects the string to represent a
- : base 10 number. strtol() allows you to select the expected number base.
-
- Also strtol will set it's second parameter (if supplied) to point to the charater
- that terminate the scan. This allows you to continue processing the buffer.
-
- For example:
-
- char* p;
- char* ptr;
- ...
- fgets(buf, sizeof(buf), stdin);
- ptr = buf;
-
- for (;;) {
- num = strtol(ptr, &p, 0);
- if (errno && errno != ERANGE) /* We can deal with ERANGE problems. */
- deal with error.
-
- if (p == ptr) {
- if (end of buf)
- break;
- deal with bad formed input
- } else
- ptr = p;
-
- do something with num
- }
-
- Regards
-
- -A.
- --
- | A.Champion |
-